// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

     // 确认、删除、添加 按钮
     @property(cc.Button)
     submit: cc.Button = null
     @property(cc.Button)
     delete: cc.Button = null
     @property(cc.Button)
     add: cc.Button=null


     @property(cc.Node)
     littleFrame: cc.Node = null;
     @property(cc.EditBox)
     inputName: cc.EditBox = null
     @property(cc.Button)
     check_btn: cc.Button = null;
     @property(cc.Node)
     mask: cc.Node = null;
     @property(cc.Node)
     up_node: cc.Node = null;
     @property(cc.Node)
     itemList: cc.Node = null;
     @property(cc.Prefab)
     itemPrefab: cc.Prefab = null;
     
     
     submit_btn(event:cc.Event.EventTouch){
         console.log('submit 跳转结果界面')
         cc.director.loadScene('result');
     }
     delete_btn(event:cc.Event.EventTouch){
         
     }
     add_btn(event:cc.Event.EventTouch){
         this.littleFrame.active = true;
         this.mask.active = true;

        //  let a = window["Win_Global"];
        //  a.add('一');
        //  var item = cc.instantiate(this.itemPrefab);
        //  var i = a.items.length -1;
        //  var data = a.items[i];
        //  this.itemList.getChildByName('wordLayout').addChild(item);
        //  item.getComponent('WordTemplate').init({
        //  id: i,
        //         itemName: data.itemName,
        //         itemNume: data.itemNume,
        //         itemComplex: data.itemComplex,
        //         itemPin: data.itemPin
        //     });
     }
     check(event:cc.Event.EventTouch){
         this.littleFrame.active = false;
         this.mask.active = false;
         let a = window["Win_Global"];
         a.add(this.inputName.string);
         var item = cc.instantiate(this.itemPrefab);
         var i = a.items.length -1;
         var data = a.items[i];
         this.itemList.getChildByName('wordLayout').addChild(item);
         item.getComponent('WordTemplate').init({
         id: i,
                itemName: data.itemName,
                itemNume: data.itemNume,
                itemComplex: data.itemComplex,
                itemPin: data.itemPin
            });
     }
     onLoad () {
        //界面设置
        this.mask.active = false;
        this.littleFrame.active = false;

        let a = window["Win_Global"];
        console.log(a)
        a.to_String()
        a.testFunction()
        for (var i = 0; i < a.items.length; ++i) {
            var item = cc.instantiate(this.itemPrefab);
            var data = a.items[i];
            this.itemList.getChildByName('wordLayout').addChild(item);
            item.getComponent('WordTemplate').init({
                id: i,
                itemName: data.itemName,
                itemNume: data.itemNume,
                itemComplex: data.itemComplex,
                itemPin: data.itemPin
            });
        }

        this.submit.node.on(cc.Node.EventType.TOUCH_END, this.submit_btn, this);
        this.delete.node.on(cc.Node.EventType.TOUCH_END, this.delete_btn,this);
        this.add.node.on(cc.Node.EventType.TOUCH_END, this.add_btn,this);
        this.check_btn.node.on(cc.Node.EventType.TOUCH_END,this.check,this);
     }
 
     start () {
     }
 
     update (dt) {}
}
